package com.wisezone.demo0216;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPServer {
	public static void main(String[] args) {
		try {
//			����DatagramSocket���������������ݣ��˿�Ϊ5000
			DatagramSocket receiveSocket = new DatagramSocket(5000);
			byte buf[] = new byte[1000];
			DatagramPacket receivePacket = new DatagramPacket(buf, buf.length);
			System.out.println("startinig to receive packet");
			while (true) {
//				ʹ��DatagramSocket�������ݱ�
				receiveSocket.receive(receivePacket);
//				�������ݱ��е���Ϣ��������������˿ڡ����ݵ�
				String name = receivePacket.getAddress().toString();
				System.out.println("����������" + name + "�˿ڣ�"
						+ receivePacket.getPort());
				String s = new String(receivePacket.getData(), 0,
						receivePacket.getLength());
				System.out.println("��������: " + s);
			}
		} catch (SocketException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (IOException e) {
			System.out.println(e);
		}

	}
}
